#!/usr/bin/python
# -*- encoding: utf-8

import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from keras.models import Sequential
from keras.layers import Dense, Dropout
from keras.layers import LSTM
from keras.layers.embeddings import Embedding
from keras.preprocessing import sequence
import warnings, time

if __name__ == '__main__':
    warnings.filterwarnings("ignore")
    np.set_printoptions(linewidth=1000)
    path = u'~/rongshi/data/stock_selection_data/monthly/end/feature_v2/training/12m_3_18/201501-201512_train.csv'
    data = pd.read_csv(path)
    x = data[['mkt_freeshares_rank', 'mmt_rank', 'mfd_buyamt_d4_rank']]
    y = data[['yield_class']]

    x_train, x_test, y_train, y_test = train_test_split(x, y, train_size=0.8, test_size=0.2)
    x_shape = x_train.shape
    x_train = x_train.values.reshape(1, x_shape[0], x_shape[1])

    y_train = y_train.values
    #y_shape = y_train.shape
    #y_train = y_train.values.reshape(1, y_shape[0], y_shape[1])

    model = Sequential()
    model.add(LSTM(input_shape=(1, x_shape[0], x_shape[1]), output_dim=50, return_sequences=True))
    model.add(LSTM(100, return_sequences=False))
    model.add(Dropout(0.2))
    model.add(Dense(1, activation='sigmoid'))

    start = time.time()
    model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
    print("> Compilation Time : ", time.time() - start)

    model.fit(x_train, y_train)

